#include "lolevel.h"
#include "platform.h"
#include "core.h"

static long *nrflag = (long*)0x7FD0; /* S90 above "aShuttersoundta" usage @FF966918 @101a */

#include "../../../generic/capt_seq.c"

void __attribute__((naked,noinline)) capt_seq_task() {


	asm volatile (
        "STMFD   SP!, {R3-R9,LR}\n"
        "LDR     R6, =0x2C58\n"
        "LDR     R4, =0x39F60\n"
        "MOV     R9, #1\n"
        "MOV     R7, #0\n"
"loc_FF87A26C:\n"
        "LDR     R0, [R6,#4]\n"
        "MOV     R2, #0\n"
        "MOV     R1, SP\n"
        "BL      sub_FF8382FC    \n"
        "TST     R0, #1\n"
        "BEQ     loc_FF87A298\n"
        "LDR     R1, =0x5B3\n"
        "LDR     R0, =0xFF879A7C\n"
        "BL      sub_FF81E88C\n"
        "BL      sub_FF81E844    \n"
        "LDMFD   SP!, {R3-R9,PC}\n"
"loc_FF87A298:\n"
        "LDR     R0, [SP]\n"
        "LDR     R1, [R0]\n"
        "CMP     R1, #0x21\n"
        "ADDLS   PC, PC, R1,LSL#2\n"
        "B       loc_FF87A55C\n"
"loc_FF87A2AC:\n"
        "B       loc_FF87A334\n"
"loc_FF87A2B0:\n"
        "B       loc_FF87A3A0\n"
"loc_FF87A2B4:\n"
        "B       loc_FF87A3DC\n"
"loc_FF87A2B8:\n"
        "B       loc_FF87A3F0\n"
"loc_FF87A2BC:\n"
        "B       loc_FF87A3E8\n"
"loc_FF87A2C0:\n"
        "B       loc_FF87A3F8\n"
"loc_FF87A2C4:\n"
        "B       loc_FF87A400\n"
"loc_FF87A2C8:\n"
        "B       loc_FF87A408\n"
"loc_FF87A2CC:\n"
        "B       loc_FF87A460\n"
"loc_FF87A2D0:\n"
        "B       loc_FF87A488\n"
"loc_FF87A2D4:\n"
        "B       loc_FF87A46C\n"
"loc_FF87A2D8:\n"
        "B       loc_FF87A478\n"
"loc_FF87A2DC:\n"
        "B       loc_FF87A480\n"
"loc_FF87A2E0:\n"
        "B       loc_FF87A490\n"
"loc_FF87A2E4:\n"
        "B       loc_FF87A498\n"
"loc_FF87A2E8:\n"
        "B       loc_FF87A4A0\n"
"loc_FF87A2EC:\n"
        "B       loc_FF87A4A8\n"
"loc_FF87A2F0:\n"
        "B       loc_FF87A4B0\n"
"loc_FF87A2F4:\n"
        "B       loc_FF87A4B8\n"
"loc_FF87A2F8:\n"
        "B       loc_FF87A4C0\n"
"loc_FF87A2FC:\n"
        "B       loc_FF87A4C8\n"
"loc_FF87A300:\n"
        "B       loc_FF87A4D0\n"
"loc_FF87A304:\n"
        "B       loc_FF87A4D8\n"
"loc_FF87A308:\n"
        "B       loc_FF87A4E4\n"
"loc_FF87A30C:\n"
        "B       loc_FF87A4EC\n"
"loc_FF87A310:\n"
        "B       loc_FF87A4F8\n"
"loc_FF87A314:\n"
        "B       loc_FF87A500\n"
"loc_FF87A318:\n"
        "B       loc_FF87A508\n"
"loc_FF87A31C:\n"
        "B       loc_FF87A510\n"
"loc_FF87A320:\n"
        "B       loc_FF87A518\n"
"loc_FF87A324:\n"
        "B       loc_FF87A520\n"
"loc_FF87A328:\n"
        "B       loc_FF87A528\n"
"loc_FF87A32C:\n"
        "B       loc_FF87A534\n"
"loc_FF87A330:\n"
        "B       loc_FF87A568\n"
"loc_FF87A334:\n"
        "BL      sub_FF87AB70\n"
		"BL      shooting_expo_param_override\n"  // + 		
        "BL      sub_FF877BC0\n"
// copied over from SX10 don't know if we need it yet
//  this code added to avoid some incorrect behavior if overrides are used.
//  but it can cause some unexpected side effects. In this case, remove this code!
                 "MOV     R0, #0\n"
                 "STR     R0, [R4,#0x24]\n"  // fixes overrides  behavior at short shutter press
 //  end of my code
 		
        "LDR     R0, [R4,#0x24]\n"
        "CMP     R0, #0\n"
        "BEQ     loc_FF87A568\n"
        "BL      sub_FF879750\n"
        "MOV     R5, R0\n"
        "LDR     R0, [R4,#0x24]\n"
        "CMP     R0, #0\n"
        "BEQ     loc_FF87A37C\n"
        "MOV     R0, #0xC\n"
        "BL      sub_FF87F9A8\n"
        "TST     R0, #1\n"
        "STRNE   R9, [R6,#0x10]\n"
        "LDRNE   R0, [R5,#8]\n"
        "ORRNE   R0, R0, #0x40000000\n"
        "STRNE   R0, [R5,#8]\n"
        "BNE     loc_FF87A568\n"
"loc_FF87A37C:\n"
        "MOV     R0, R5\n"
        "BL      sub_FF966224\n"
        "MOV     R0, R5\n"
        "BL      sub_FF879B30\n"
        "MOV     R0, R5\n"
        //"BL      sub_FF966AC0    \n"
		"BL      sub_FF966AC0_my\n" // -------------->
		"BL      capt_seq_hook_raw_here\n"      // +		
        "TST     R0, #1\n"
        "STRNE   R9, [R6,#0x10]\n"
        "B       loc_FF87A568\n"
"loc_FF87A3A0:\n"
        "LDR     R0, [R4,#0x24]\n"
        "CMP     R0, #0\n"
        "BNE     loc_FF87A3CC\n"
        "MOV     R0, #0xC\n"
        "BL      sub_FF87F9A8\n"
        "TST     R0, #1\n"
        "LDRNE   R0, [SP]\n"
        "MOVNE   R1, #1\n"
        "LDRNE   R2, [R0,#0xC]\n"
        "MOVNE   R0, #1\n"
        "BNE     loc_FF87A458\n"
"loc_FF87A3CC:\n"
        "LDR     R0, [SP]\n"
        //"BL      sub_FF879BA8\n" //- capt_seq_hook ist called in this subroutine
		"BL      sub_FF879BA8_my\n" //---------->
"loc_FF87A3D4:\n"
        "STR     R7, [R4,#0x24]\n"
        "B       loc_FF87A568\n"
"loc_FF87A3DC:\n"
        "MOV     R0, #1\n"
        "BL      sub_FF87ADC4    \n"
        "B       loc_FF87A568\n"
"loc_FF87A3E8:\n"
        "BL      sub_FF87A820\n"
        "B       loc_FF87A3D4\n"
"loc_FF87A3F0:\n"
        "BL      sub_FF87AB50\n"
        "B       loc_FF87A3D4\n"
"loc_FF87A3F8:\n"
        "BL      sub_FF87AB58\n"
        "B       loc_FF87A568\n"
"loc_FF87A400:\n"
        "BL      sub_FF87ACE4\n"
        "B       loc_FF87A464\n"
"loc_FF87A408:\n"
        "LDR     R5, [R0,#0xC]\n"
        "BL      sub_FF87AB60\n"
        "MOV     R0, R5\n"
        "BL      sub_FF9656B0    \n"
        "TST     R0, #1\n"
        "MOV     R8, R0\n"
        "BNE     loc_FF87A448\n"
        "BL      sub_FF88CC70    \n"
        "STR     R0, [R5,#0x18]\n"
        "MOV     R0, R5\n"
        "BL      sub_FF9669D8    \n"
        "MOV     R0, R5\n"
        "BL      sub_FF966DD8    \n"
        "MOV     R8, R0\n"
        "LDR     R0, [R5,#0x18]\n"
        "BL      sub_FF88CE84    \n"
"loc_FF87A448:\n"
        "BL      sub_FF87AB50\n"
        "MOV     R2, R5\n"
        "MOV     R1, #9\n"
        "MOV     R0, R8\n"
"loc_FF87A458:\n"
        "BL      sub_FF878128    \n"
        "B       loc_FF87A568\n"
"loc_FF87A460:\n"
        "BL      sub_FF87AD44\n"
"loc_FF87A464:\n"
        "BL      sub_FF877BC0\n"
        "B       loc_FF87A568\n"
"loc_FF87A46C:\n"
        "LDR     R0, [R4,#0x54]\n"
        "BL      sub_FF87B624    \n"
        "B       loc_FF87A568\n"
"loc_FF87A478:\n"
        "BL      sub_FF87B8D8\n"
        "B       loc_FF87A568\n"
"loc_FF87A480:\n"
        "BL      sub_FF87B96C\n"
        "B       loc_FF87A568\n"
"loc_FF87A488:\n"
        "BL      sub_FF87AB50\n"
        "B       loc_FF87A568\n"
"loc_FF87A490:\n"
        "BL      sub_FF9658CC\n"
        "B       loc_FF87A568\n"
"loc_FF87A498:\n"
        "BL      sub_FF965AE0\n"
        "B       loc_FF87A568\n"
"loc_FF87A4A0:\n"
        "BL      sub_FF965B68\n"
        "B       loc_FF87A568\n"
"loc_FF87A4A8:\n"
        "BL      sub_FF965C58\n"
        "B       loc_FF87A568\n"
"loc_FF87A4B0:\n"
        "BL      sub_FF965D4C\n"
        "B       loc_FF87A568\n"
"loc_FF87A4B8:\n"
        "MOV     R0, #0\n"
        "B       loc_FF87A4DC\n"
"loc_FF87A4C0:\n"
        "BL      sub_FF965F68\n"
        "B       loc_FF87A568\n"
"loc_FF87A4C8:\n"
        "BL      sub_FF965FF8\n"
        "B       loc_FF87A568\n"
"loc_FF87A4D0:\n"
        "BL      sub_FF9660B8\n"
        "B       loc_FF87A568\n"
"loc_FF87A4D8:\n"
        "MOV     R0, #1\n"
"loc_FF87A4DC:\n"
        "BL      sub_FF965E18\n"
        "B       loc_FF87A568\n"
"loc_FF87A4E4:\n"
        "BL      sub_FF87AFAC\n"
        "B       loc_FF87A568\n"
"loc_FF87A4EC:\n"
        "BL      sub_FF87B04C\n"
        "BL      sub_FF87A690    \n"
        "B       loc_FF87A568\n"
"loc_FF87A4F8:\n"
        "BL      sub_FF87B3C0\n"
        "B       loc_FF87A568\n"
"loc_FF87A500:\n"
        "BL      sub_FF87B4DC\n"
        "B       loc_FF87A568\n"
"loc_FF87A508:\n"
        "BL      sub_FF879A08\n"
        "B       loc_FF87A568\n"
"loc_FF87A510:\n"
        "BL      sub_FF835FDC\n"
        "B       loc_FF87A568\n"
"loc_FF87A518:\n"
        "BL      sub_FF87DD2C\n"
        "B       loc_FF87A568\n"
"loc_FF87A520:\n"
        "BL      sub_FF87DD94\n"
        "B       loc_FF87A568\n"
"loc_FF87A528:\n"
        "BL      sub_FF87DDF0\n"
        "BL      sub_FF87DDB0\n"
        "B       loc_FF87A568\n"
"loc_FF87A534:\n"
        "MOV     R0, #1\n"
        "BL      sub_FF967640\n"
        "MOV     R0, #1\n"
        "BL      sub_FF967750\n"
        "LDRH    R0, [R4,#0xA0]\n"
        "CMP     R0, #4\n"
        "BNE     loc_FF87A568\n"
        "BL      sub_FF87DD94\n"
        "BL      sub_FF87E1DC\n"
        "B       loc_FF87A568\n"
"loc_FF87A55C:\n"
        "LDR     R1, =0x708\n"
        "LDR     R0, =0xFF879A7C\n"
        "BL      sub_FF81E88C\n"
"loc_FF87A568:\n"
        "LDR     R0, [SP]\n"
        "LDR     R1, [R0,#4]\n"
        "LDR     R0, [R6]\n"
        "BL      sub_FF88495C\n"
        "LDR     R5, [SP]\n"
        "LDR     R0, [R5,#8]\n"
        "CMP     R0, #0\n"
        "LDREQ   R1, =0x131\n"
        "LDREQ   R0, =0xFF879A7C\n"
        "BLEQ    sub_FF81E88C\n"
        "STR     R7, [R5,#8]\n"
        "B       loc_FF87A26C\n"
 );
}


void __attribute__((naked,noinline)) sub_FF879BA8_my() { //2
 asm volatile (
        "STMFD   SP!, {R3-R9,LR}\n"
        "LDR     R4, [R0,#0xC]\n"
        "LDR     R5, =0x39F60\n"
        "LDR     R0, [R4,#8]\n"
        "LDR     R6, =0x420A\n"
        "ORR     R0, R0, #1\n"
        "STR     R0, [R4,#8]\n"
        "LDRH    R0, [R5]\n"
        "LDR     R8, =0x2C58\n"
        "MOV     R7, #0\n"
        "CMP     R0, R6\n"
        "BEQ     loc_FF879C4C\n"
        "LDRH    R0, [R5,#0x9E]\n"
        "CMP     R0, #3\n"
        "BEQ     loc_FF879CAC\n"
        "LDR     R0, [R4,#0xC]\n"
        "CMP     R0, #1\n"
        "BLS     loc_FF879C58\n"
        "LDRH    R0, [R5,#0x9C]\n"
        "CMP     R0, #0\n"
        "BNE     loc_FF879CAC\n"
        "LDRH    R0, [R5,#0x98]\n"
        "CMP     R0, #2\n"
        "BNE     loc_FF879C64\n"
        "BL      sub_FF87B0FC\n"
        "LDRH    R0, [R5]\n"
        "CMP     R0, R6\n"
        "BEQ     loc_FF879C4C\n"
        "LDRH    R0, [R5,#0x9E]\n"
        "CMP     R0, #3\n"
        "BEQ     loc_FF879CAC\n"
        "LDR     R0, [R4,#0xC]\n"
        "CMP     R0, #1\n"
        "BLS     loc_FF879C58\n"
        "LDRH    R0, [R5,#0x9C]\n"
        "CMP     R0, #0\n"
        "BNE     loc_FF879CAC\n"
        "LDRH    R0, [R5,#0x98]\n"
        "CMP     R0, #2\n"
        "BEQ     loc_FF879C90\n"
        "B       loc_FF879C64\n"
"loc_FF879C4C:\n"
        "LDRH    R0, [R5,#0x9E]\n"
        "CMP     R0, #3\n"
        "BEQ     loc_FF879CAC\n"
"loc_FF879C58:\n"
        "LDRH    R0, [R5,#0x9C]\n"
        "CMP     R0, #0\n"
        "BNE     loc_FF879CAC\n"
"loc_FF879C64:\n"
        "LDRH    R0, [R5,#0x98]\n"
        "CMP     R0, #1\n"
        "BNE     loc_FF879CAC\n"
        "LDRH    R0, [R5]\n"
        "CMP     R0, R6\n"
        "LDRNE   R0, [R4,#0xC]\n"
        "CMPNE   R0, #1\n"
        "BLS     loc_FF879CAC\n"
        "LDR     R0, [R4,#0x10]\n"
        "CMP     R0, #1\n"
        "BNE     loc_FF879CAC\n"
"loc_FF879C90:\n"
        "MOV     R3, #0x268\n"
        "STR     R3, [SP]\n"
        "LDR     R0, [R8]\n"
        "LDR     R2, =0xEA60\n"
        "LDR     R3, =0xFF879A7C\n"
        "MOV     R1, #0x40000000\n"
        "BL      sub_FF87FD08\n"
"loc_FF879CAC:\n"
        "BL      sub_FF879A08\n"
        "LDR     R0, [R5,#0x24]\n"
        "CMP     R0, #0\n"
        "MOVEQ   R0, #2\n"
        "BLEQ    sub_FF87632C\n"
        "BL      sub_FF87AB60\n"
        "LDR     R0, [R5,#0x24]\n"
        "CMP     R0, #0\n"
        "BNE     loc_FF879D64\n"
        "MOV     R0, #0\n"
        "BL      sub_FF967640\n"
        "MOV     R0, #0\n"
        "BL      sub_FF967750\n"
        "MOV     R0, R4\n"
        "BL      sub_FF966224\n"
        "MOV     R0, R4\n"
        "BL      sub_FF87AF28\n"
        "MOV     R0, R4\n"
        "BL      sub_FF9652A0\n"
        "CMP     R0, #0\n"
        "BEQ     loc_FF879D2C\n"
        "BL      sub_FF967680\n"
        "BL      sub_FF967794\n"
        "BL      sub_FF9677E4\n"
        "MOV     R0, R4\n"
        "BL      sub_FF9653E4    \n"
        "TST     R0, #1\n"
        "MOVNE   R2, R4\n"
        "LDMNEFD SP!, {R3-R9,LR}\n"
        "MOVNE   R1, #1\n"
        "BNE     sub_FF878128    \n"
        "B       loc_FF879D40\n"
"loc_FF879D2C:\n"
        "MOV     R0, R4\n"
        "BL      sub_FF965350\n"
        "BL      sub_FF967680\n"
        "BL      sub_FF967794\n"
        "BL      sub_FF9677E4\n"
"loc_FF879D40:\n"
        "MOV     R0, R4\n"
        "BL      sub_FF879B30\n"
        "MOV     R0, R4\n"
        "BL      sub_FF9669D8    \n"
        "BL      sub_FF967458    \n"
        "MOV     R0, R4\n"
        //"BL      sub_FF966AC0    \n"
		"BL      sub_FF966AC0_my\n" // ------------------>
        "MOV     R7, R0\n"
		"BL      capt_seq_hook_raw_here\n"      // +
        "B       loc_FF879D70\n"
"loc_FF879D64:\n"
        "LDR     R0, [R8,#0x10]\n"
        "CMP     R0, #0\n"
        "MOVNE   R7, #0x1D\n"
"loc_FF879D70:\n"
        "BL      sub_FF87DD94\n"
        "BL      sub_FF87DDDC\n"
        "BL      sub_FF87DE1C\n"
        "MOV     R2, R4\n"
        "MOV     R1, #1\n"
        "MOV     R0, R7\n"
        "BL      sub_FF878128    \n"
        "BL      sub_FF966D7C\n"
        "CMP     R0, #0\n"
        "LDRNE   R0, [R4,#8]\n"
        "ORRNE   R0, R0, #0x2000\n"
        "STRNE   R0, [R4,#8]\n"
        "LDRH    R0, [R5,#0x9E]\n"
        "CMP     R0, #3\n"
        "BEQ     locret_FF879DC8\n"
        "LDRH    R0, [R5,#0x9C]\n"
        "CMP     R0, #0\n"
        "LDREQH  R0, [R5,#0x98]\n"
        "CMPEQ   R0, #2\n"
        "MOVEQ   R0, R4\n"
        "LDMEQFD SP!, {R3-R9,LR}\n"
        "BEQ     sub_FF87B150\n"
"locret_FF879DC8:\n"
        "LDMFD   SP!, {R3-R9,PC}\n"
 );
}

void __attribute__((naked,noinline)) sub_FF966AC0_my() { 
 asm volatile (
        "STMFD   SP!, {R0-R8,LR}\n"
        "MOV     R4, R0\n"
        "BL      sub_FF96793C    \n"
        "MVN     R1, #0\n"
        "BL      sub_FF884990\n"
        "LDR     R5, =0x7FD0\n"
        "LDR     R0, [R5,#0xC]\n"
        "CMP     R0, #0\n"
        "BNE     loc_FF966B10\n"
        "MOV     R1, #1\n"
        "MOV     R0, #0\n"
        "BL      sub_FF838B44    \n"
        "STR     R0, [R5,#0xC]\n"
        "MOV     R3, #0\n"
        "STR     R3, [SP]\n"
        "LDR     R3, =0xFF96644C \n"
        "LDR     R0, =0xFF966D40\n"
        "MOV     R2, #0x400\n"
        "MOV     R1, #0x17\n"
        "BL      sub_FF838B10    \n"
"loc_FF966B10:\n"
        "MOV     R2, #4\n"
        "ADD     R1, SP, #8\n"
        "MOV     R0, #0x8A\n"
        "BL      sub_FF88CAE0    \n"
        "TST     R0, #1\n"
        "LDRNE   R1, =0x3C5\n"
        "LDRNE   R0, =0xFF9666E4\n"
        "BLNE    sub_FF81E88C\n"
        "LDR     R6, =0x3A02C\n"
        "LDR     R8, =0x39F60\n"
        "LDR     R3, [R6]\n"
        "LDRSH   R2, [R6,#0xC]\n"
        "LDRSH   R1, [R6,#0xE]\n"
        "LDR     R0, [R8,#0x94]\n"
        "BL      sub_FF92E194\n"
        "BL      sub_FF86157C    \n"
        "LDR     R3, =0x7FD8\n"
        "STRH    R0, [R4,#0xA4]\n"
        "SUB     R2, R3, #4\n"
        "STRD    R2, [SP]\n"
        "MOV     R1, R0\n"
        "LDRH    R0, [R8,#0x5C]\n"
        "LDRSH   R2, [R6,#0xC]\n"
        "SUB     R3, R3, #8\n"
        "BL      sub_FF96965C\n"
        "BL      wait_until_remote_button_is_released\n"  // +
        "BL      capt_seq_hook_set_nr\n"                  // +   
        "B       sub_FF966B74\n" // +  Jump back to original FW code
 );
}

void __attribute__((naked,noinline)) exp_drv_task(){
 asm volatile(
        "STMFD   SP!, {R4-R8,LR}\n"
        "SUB     SP, SP, #0x20\n"
        "LDR     R8, =0xBB8\n"
        "LDR     R7, =0x4440\n"
        "LDR     R5, =0x4372C\n"
        "MOV     R0, #0\n"
        "ADD     R6, SP, #0x10\n"
        "STR     R0, [SP,#0xC]\n"
"loc_FF8C0EF0:\n"
        "LDR     R0, [R7,#0x20]\n"
        "MOV     R2, #0\n"
        "ADD     R1, SP, #0x1C\n"
        "BL      sub_FF8382FC    \n"
        "LDR     R0, [SP,#0xC]\n"
        "CMP     R0, #1\n"
        "BNE     loc_FF8C0F3C\n"
        "LDR     R0, [SP,#0x1C]\n"
        "LDR     R0, [R0]\n"
        "CMP     R0, #0x13\n"
        "CMPNE   R0, #0x14\n"
        "CMPNE   R0, #0x15\n"
        "CMPNE   R0, #0x16\n"
        "BEQ     loc_FF8C10A0\n"
        "CMP     R0, #0x28\n"
        "BEQ     loc_FF8C1028\n"
        "ADD     R1, SP, #0xC\n"
        "MOV     R0, #0\n"
        "BL      sub_FF8C0E80    \n"
"loc_FF8C0F3C:\n"
        "LDR     R0, [SP,#0x1C]\n"
        "LDR     R1, [R0]\n"
        "CMP     R1, #0x2E\n"
        "BNE     loc_FF8C0F6C\n"
        "LDR     R0, [SP,#0x1C]\n"
        "BL      sub_FF8C21D8    \n"
        "LDR     R0, [R7,#0x1C]\n"
        "MOV     R1, #1\n"
        "BL      sub_FF88495C\n"
        "BL      sub_FF81E844    \n"
        "ADD     SP, SP, #0x20\n"
        "LDMFD   SP!, {R4-R8,PC}\n"
"loc_FF8C0F6C:\n"
        "CMP     R1, #0x2D\n"
        "BNE     loc_FF8C0F88\n"
        "LDR     R2, [R0,#0x8C]!\n"
        "LDR     R1, [R0,#4]\n"
        "MOV     R0, R1\n"
        "BLX     R2\n"
        "B       loc_FF8C14C8\n"
"loc_FF8C0F88:\n"
        "CMP     R1, #0x26\n"
        "BNE     loc_FF8C0FD8\n"
        "LDR     R0, [R7,#0x1C]\n"
        "MOV     R1, #0x80\n"
        "BL      sub_FF884990\n"
        "LDR     R0, =0xFF8BD618\n"
        "MOV     R1, #0x80\n"
        "BL      sub_FF95970C    \n"
        "LDR     R0, [R7,#0x1C]\n"
        "MOV     R2, R8\n"
        "MOV     R1, #0x80\n"
        "BL      sub_FF88489C    \n"
        "TST     R0, #1\n"
        "LDRNE   R1, =0xE5F\n"
        "BNE     loc_FF8C1094\n"
"loc_FF8C0FC4:\n"
        "LDR     R1, [SP,#0x1C]\n"
        "LDR     R0, [R1,#0x90]\n"
        "LDR     R1, [R1,#0x8C]\n"
        "BLX     R1\n"
        "B       loc_FF8C14C8\n"
"loc_FF8C0FD8:\n"
        "CMP     R1, #0x27\n"
        "BNE     loc_FF8C1020\n"
        "ADD     R1, SP, #0xC\n"
        "BL      sub_FF8C0E80    \n"
        "LDR     R0, [R7,#0x1C]\n"
        "MOV     R1, #0x100\n"
        "BL      sub_FF884990\n"
        "LDR     R0, =0xFF8BD628\n"
        "MOV     R1, #0x100\n"
        "BL      sub_FF95A09C    \n"
        "LDR     R0, [R7,#0x1C]\n"
        "MOV     R2, R8\n"
        "MOV     R1, #0x100\n"
        "BL      sub_FF88489C    \n"
        "TST     R0, #1\n"
        "BEQ     loc_FF8C0FC4\n"
        "LDR     R1, =0xE69\n"
        "B       loc_FF8C1094\n"
"loc_FF8C1020:\n"
        "CMP     R1, #0x28\n"
        "BNE     loc_FF8C1038\n"
"loc_FF8C1028:\n"
        "LDR     R0, [SP,#0x1C]\n"
        "ADD     R1, SP, #0xC\n"
        "BL      sub_FF8C0E80    \n"
        "B       loc_FF8C0FC4\n"
"loc_FF8C1038:\n"
        "CMP     R1, #0x2B\n"
        "BNE     loc_FF8C1050\n"
        "BL      sub_FF8B0A7C    \n"
        "BL      sub_FF8B16A0    \n"
        "BL      sub_FF8B11F4    \n"
        "B       loc_FF8C0FC4\n"
"loc_FF8C1050:\n"
        "CMP     R1, #0x2C\n"
        "BNE     loc_FF8C10A0\n"
        "LDR     R0, [R7,#0x1C]\n"
        "MOV     R1, #4\n"
        "BL      sub_FF884990\n"
        "LDR     R1, =0xFF8BD648\n"
        "LDR     R0, =0xFFFFF400\n"
        "MOV     R2, #4\n"
        "BL      sub_FF8B04F8\n"
        "BL      sub_FF8B0780    \n"
        "LDR     R0, [R7,#0x1C]\n"
        "MOV     R2, R8\n"
        "MOV     R1, #4\n"
        "BL      sub_FF8847B8    \n"
        "TST     R0, #1\n"
        "BEQ     loc_FF8C0FC4\n"
        "LDR     R1, =0xE91\n"
"loc_FF8C1094:\n"
        "LDR     R0, =0xFF8BDC88\n"
        "BL      sub_FF81E88C\n"
        "B       loc_FF8C0FC4\n"
"loc_FF8C10A0:\n"
        "LDR     R0, [SP,#0x1C]\n"
        "MOV     R4, #1\n"
        "LDR     R1, [R0]\n"
        "CMP     R1, #0x11\n"
        "CMPNE   R1, #0x12\n"
        "BNE     loc_FF8C1110\n"
        "LDR     R1, [R0,#0x7C]\n"
        "ADD     R1, R1, R1,LSL#1\n"
        "ADD     R1, R0, R1,LSL#2\n"
        "SUB     R1, R1, #8\n"
        "LDMIA   R1, {R2-R4}\n"
        "STMIA   R6, {R2-R4}\n"
        "BL      sub_FF8BF800\n"
        "LDR     R0, [SP,#0x1C]\n"
        "LDR     R1, [R0,#0x7C]\n"
        "LDR     R3, [R0,#0x8C]\n"
        "LDR     R2, [R0,#0x90]\n"
        "ADD     R0, R0, #4\n"
        "BLX     R3\n"
        "LDR     R0, [SP,#0x1C]\n"
        "BL      sub_FF8C25A0    \n"
        "LDR     R0, [SP,#0x1C]\n"
        "LDR     R1, [R0,#0x7C]\n"
        "LDR     R3, [R0,#0x94]\n"
        "LDR     R2, [R0,#0x98]\n"
        "ADD     R0, R0, #4\n"
        "BLX     R3\n"
        "B       loc_FF8C1408\n"
"loc_FF8C1110:\n"
        "CMP     R1, #0x13\n"
        "CMPNE   R1, #0x14\n"
        "CMPNE   R1, #0x15\n"
        "CMPNE   R1, #0x16\n"
        "BNE     loc_FF8C11C8\n"
        "ADD     R3, SP, #0xC\n"
        "MOV     R2, SP\n"
        "ADD     R1, SP, #0x10\n"
        "BL      sub_FF8BFADC    \n"
        "CMP     R0, #1\n"
        "MOV     R4, R0\n"
        "CMPNE   R4, #5\n"
        "BNE     loc_FF8C1164\n"
        "LDR     R0, [SP,#0x1C]\n"
        "MOV     R2, R4\n"
        "LDR     R1, [R0,#0x7C]!\n"
        "LDR     R12, [R0,#0x10]!\n"
        "LDR     R3, [R0,#4]\n"
        "MOV     R0, SP\n"
        "BLX     R12\n"
        "B       loc_FF8C119C\n"
"loc_FF8C1164:\n"
        "LDR     R0, [SP,#0x1C]\n"
        "CMP     R4, #2\n"
        "LDR     R3, [R0,#0x90]\n"
        "CMPNE   R4, #6\n"
        "BNE     loc_FF8C11B0\n"
        "LDR     R12, [R0,#0x8C]\n"
        "MOV     R0, SP\n"
        "MOV     R2, R4\n"
        "MOV     R1, #1\n"
        "BLX     R12\n"
        "LDR     R0, [SP,#0x1C]\n"
        "MOV     R2, SP\n"
        "ADD     R1, SP, #0x10\n"
        "BL      sub_FF8C0B88    \n"
"loc_FF8C119C:\n"
        "LDR     R0, [SP,#0x1C]\n"
        "LDR     R2, [SP,#0xC]\n"
        "MOV     R1, R4\n"
        "BL      sub_FF8C0E20    \n"
        "B       loc_FF8C1408\n"
"loc_FF8C11B0:\n"
        "LDR     R1, [R0,#0x7C]\n"
        "LDR     R12, [R0,#0x8C]\n"
        "ADD     R0, R0, #4\n"
        "MOV     R2, R4\n"
        "BLX     R12\n"
        "B       loc_FF8C1408\n"
"loc_FF8C11C8:\n"
        "CMP     R1, #0x22\n"
        "CMPNE   R1, #0x23\n"
        "BNE     loc_FF8C1214\n"
        "LDR     R1, [R0,#0x7C]\n"
        "ADD     R1, R1, R1,LSL#1\n"
        "ADD     R1, R0, R1,LSL#2\n"
        "SUB     R1, R1, #8\n"
        "LDMIA   R1, {R2-R4}\n"
        "STMIA   R6, {R2-R4}\n"
        "BL      sub_FF8BED44    \n"
        "LDR     R0, [SP,#0x1C]\n"
        "LDR     R1, [R0,#0x7C]\n"
        "LDR     R3, [R0,#0x8C]\n"
        "LDR     R2, [R0,#0x90]\n"
        "ADD     R0, R0, #4\n"
        "BLX     R3\n"
        "LDR     R0, [SP,#0x1C]\n"
        "BL      sub_FF8BF044    \n"
        "B       loc_FF8C1408\n"
"loc_FF8C1214:\n"
        "ADD     R1, R0, #4\n"
        "LDMIA   R1, {R2,R3,R12}\n"
        "STMIA   R6, {R2,R3,R12}\n"
        "LDR     R1, [R0]\n"
        "CMP     R1, #0x25\n"
        "ADDLS   PC, PC, R1,LSL#2\n"
        "B       loc_FF8C13E8\n"
"loc_FF8C1230:\n"
        "B       loc_FF8C12C8\n"
"loc_FF8C1234:\n"
        "B       loc_FF8C12C8\n"
"loc_FF8C1238:\n"
        "B       loc_FF8C12D0\n"
"loc_FF8C123C:\n"
        "B       loc_FF8C12D8\n"
"loc_FF8C1240:\n"
        "B       loc_FF8C12D8\n"
"loc_FF8C1244:\n"
        "B       loc_FF8C12D8\n"
"loc_FF8C1248:\n"
        "B       loc_FF8C12C8\n"
"loc_FF8C124C:\n"
        "B       loc_FF8C12D0\n"
"loc_FF8C1250:\n"
        "B       loc_FF8C12D8\n"
"loc_FF8C1254:\n"
        "B       loc_FF8C12D8\n"
"loc_FF8C1258:\n"
        "B       loc_FF8C12F0\n"
"loc_FF8C125C:\n"
        "B       loc_FF8C12F0\n"
"loc_FF8C1260:\n"
        "B       loc_FF8C13DC\n"
"loc_FF8C1264:\n"
        "B       loc_FF8C13E4\n"
"loc_FF8C1268:\n"
        "B       loc_FF8C13E4\n"
"loc_FF8C126C:\n"
        "B       loc_FF8C13E4\n"
"loc_FF8C1270:\n"
        "B       loc_FF8C13E4\n"
"loc_FF8C1274:\n"
        "B       loc_FF8C13E8\n"
"loc_FF8C1278:\n"
        "B       loc_FF8C13E8\n"
"loc_FF8C127C:\n"
        "B       loc_FF8C13E8\n"
"loc_FF8C1280:\n"
        "B       loc_FF8C13E8\n"
"loc_FF8C1284:\n"
        "B       loc_FF8C13E8\n"
"loc_FF8C1288:\n"
        "B       loc_FF8C13E8\n"
"loc_FF8C128C:\n"
        "B       loc_FF8C12E0\n"
"loc_FF8C1290:\n"
        "B       loc_FF8C12E8\n"
"loc_FF8C1294:\n"
        "B       loc_FF8C12E8\n"
"loc_FF8C1298:\n"
        "B       loc_FF8C12FC\n"
"loc_FF8C129C:\n"
        "B       loc_FF8C12FC\n"
"loc_FF8C12A0:\n"
        "B       loc_FF8C1304\n"
"loc_FF8C12A4:\n"
        "B       loc_FF8C1334\n"
"loc_FF8C12A8:\n"
        "B       loc_FF8C1364\n"
"loc_FF8C12AC:\n"
        "B       loc_FF8C1394\n"
"loc_FF8C12B0:\n"
        "B       loc_FF8C13C4\n"
"loc_FF8C12B4:\n"
        "B       loc_FF8C13C4\n"
"loc_FF8C12B8:\n"
        "B       loc_FF8C13E8\n"
"loc_FF8C12BC:\n"
        "B       loc_FF8C13E8\n"
"loc_FF8C12C0:\n"
        "B       loc_FF8C13CC\n"
"loc_FF8C12C4:\n"
        "B       loc_FF8C13D4\n"
"loc_FF8C12C8:\n"
        "BL      sub_FF8BDB30\n"
        "B       loc_FF8C13E8\n"
"loc_FF8C12D0:\n"
        "BL      sub_FF8BDDB4\n"
        "B       loc_FF8C13E8\n"
"loc_FF8C12D8:\n"
        "BL      sub_FF8BDFBC\n"
        "B       loc_FF8C13E8\n"
"loc_FF8C12E0:\n"
        "BL      sub_FF8BE234\n"
        "B       loc_FF8C13E8\n"
"loc_FF8C12E8:\n"
        "BL      sub_FF8BE42C\n"
        "B       loc_FF8C13E8\n"
"loc_FF8C12F0:\n" // ; jumptable FF8C1228 entries 10,11 
        //"BL      sub_FF8BE6E8\n"
		"BL      sub_FF8BE6E8_my\n" // ----------------->
        "MOV     R4, #0\n"
        "B       loc_FF8C13E8\n"
"loc_FF8C12FC:\n"
        "BL      sub_FF8BE828\n"
        "B       loc_FF8C13E8\n"
"loc_FF8C1304:\n"
        "LDRH    R1, [R0,#4]\n"
        "STRH    R1, [SP,#0x10]\n"
        "LDRH    R1, [R5,#2]\n"
        "STRH    R1, [SP,#0x12]\n"
        "LDRH    R1, [R5,#4]\n"
        "STRH    R1, [SP,#0x14]\n"
        "LDRH    R1, [R5,#6]\n"
        "STRH    R1, [SP,#0x16]\n"
        "LDRH    R1, [R0,#0xC]\n"
        "STRH    R1, [SP,#0x18]\n"
        "BL      sub_FF8C224C    \n"
        "B       loc_FF8C13E8\n"
"loc_FF8C1334:\n"
        "LDRH    R1, [R0,#4]\n"
        "STRH    R1, [SP,#0x10]\n"
        "LDRH    R1, [R5,#2]\n"
        "STRH    R1, [SP,#0x12]\n"
        "LDRH    R1, [R5,#4]\n"
        "STRH    R1, [SP,#0x14]\n"
        "LDRH    R1, [R5,#6]\n"
        "STRH    R1, [SP,#0x16]\n"
        "LDRH    R1, [R5,#8]\n"
        "STRH    R1, [SP,#0x18]\n"
        "BL      sub_FF8C23B8    \n"
        "B       loc_FF8C13E8\n"
"loc_FF8C1364:\n"
        "LDRH    R1, [R5]\n"
        "STRH    R1, [SP,#0x10]\n"
        "LDRH    R1, [R0,#6]\n"
        "STRH    R1, [SP,#0x12]\n"
        "LDRH    R1, [R5,#4]\n"
        "STRH    R1, [SP,#0x14]\n"
        "LDRH    R1, [R5,#6]\n"
        "STRH    R1, [SP,#0x16]\n"
        "LDRH    R1, [R5,#8]\n"
        "STRH    R1, [SP,#0x18]\n"
        "BL      sub_FF8C2464    \n"
        "B       loc_FF8C13E8\n"
"loc_FF8C1394:\n"
        "LDRH    R1, [R5]\n"
        "STRH    R1, [SP,#0x10]\n"
        "LDRH    R1, [R5,#2]\n"
        "STRH    R1, [SP,#0x12]\n"
        "LDRH    R1, [R5,#4]\n"
        "STRH    R1, [SP,#0x14]\n"
        "LDRH    R1, [R5,#6]\n"
        "STRH    R1, [SP,#0x16]\n"
        "LDRH    R1, [R0,#0xC]\n"
        "STRH    R1, [SP,#0x18]\n"
        "BL      sub_FF8C2504    \n"
        "B       loc_FF8C13E8\n"
"loc_FF8C13C4:\n"
        "BL      sub_FF8BEB80\n"
        "B       loc_FF8C13E8\n"
"loc_FF8C13CC:\n"
        "BL      sub_FF8BF148\n"
        "B       loc_FF8C13E8\n"
"loc_FF8C13D4:\n"
        "BL      sub_FF8BF384\n"
        "B       loc_FF8C13E8\n"
"loc_FF8C13DC:\n"
        "BL      sub_FF8BF500\n"
        "B       loc_FF8C13E8\n"
"loc_FF8C13E4:\n"
        "BL      sub_FF8BF69C\n"
"loc_FF8C13E8:\n"
        "LDR     R0, [SP,#0x1C]\n"
        "LDR     R1, [R0,#0x7C]\n"
        "LDR     R3, [R0,#0x8C]\n"
        "LDR     R2, [R0,#0x90]\n"
        "ADD     R0, R0, #4\n"
        "BLX     R3\n"
        "CMP     R4, #1\n"
        "BNE     loc_FF8C1450\n"
"loc_FF8C1408:\n"
        "LDR     R0, [SP,#0x1C]\n"
        "MOV     R2, #0xC\n"
        "LDR     R1, [R0,#0x7C]\n"
        "ADD     R1, R1, R1,LSL#1\n"
        "ADD     R0, R0, R1,LSL#2\n"
        "SUB     R4, R0, #8\n"
        "LDR     R0, =0x4372C\n"
        "ADD     R1, SP, #0x10\n"
        "BL      sub_FFB34DD8\n"
        "LDR     R0, =0x43738\n"
        "MOV     R2, #0xC\n"
        "ADD     R1, SP, #0x10\n"
        "BL      sub_FFB34DD8\n"
        "LDR     R0, =0x43744\n"
        "MOV     R2, #0xC\n"
        "MOV     R1, R4\n"
        "BL      sub_FFB34DD8\n"
        "B       loc_FF8C14C8\n"
"loc_FF8C1450:\n"
        "LDR     R0, [SP,#0x1C]\n"
        "LDR     R0, [R0]\n"
        "CMP     R0, #0xB\n"
        "BNE     loc_FF8C1498\n"
        "MOV     R3, #0\n"
        "STR     R3, [SP]\n"
        "MOV     R3, #1\n"
        "MOV     R2, #1\n"
        "MOV     R1, #1\n"
        "MOV     R0, #0\n"
        "BL      sub_FF8BD938\n"
        "MOV     R3, #0\n"
        "STR     R3, [SP]\n"
        "MOV     R3, #1\n"
        "MOV     R2, #1\n"
        "MOV     R1, #1\n"
        "MOV     R0, #0\n"
        "B       loc_FF8C14C4\n"
"loc_FF8C1498:\n"
        "MOV     R3, #1\n"
        "MOV     R2, #1\n"
        "MOV     R1, #1\n"
        "MOV     R0, #1\n"
        "STR     R3, [SP]\n"
        "BL      sub_FF8BD938\n"
        "MOV     R3, #1\n"
        "MOV     R2, #1\n"
        "MOV     R1, #1\n"
        "MOV     R0, #1\n"
        "STR     R3, [SP]\n"
"loc_FF8C14C4:\n"
        "BL      sub_FF8BDA78\n"
"loc_FF8C14C8:\n"
        "LDR     R0, [SP,#0x1C]\n"
        "BL      sub_FF8C21D8    \n"
        "B       loc_FF8C0EF0\n"
		);
};

void __attribute__((naked,noinline)) sub_FF8BE6E8_my(){
 asm volatile(
        "STMFD   SP!, {R4-R8,LR}\n"
        "LDR     R7, =0x4440\n"
        "MOV     R4, R0\n"
        "LDR     R0, [R7,#0x1C]\n"
        "MOV     R1, #0x3E\n"
        "BL      sub_FF884990\n"
        "LDRSH   R0, [R4,#4]\n"
        "MOV     R2, #0\n"
        "MOV     R1, #0\n"
        "BL      sub_FF8BD69C\n"
        "MOV     R6, R0\n"
        "LDRSH   R0, [R4,#6]\n"
        "BL      sub_FF8BD7AC\n"
        "LDRSH   R0, [R4,#8]\n"
        "BL      sub_FF8BD804\n"
        "LDRSH   R0, [R4,#0xA]\n"
        "BL      sub_FF8BD85C\n"
        "LDRSH   R0, [R4,#0xC]\n"
        "MOV     R1, #0\n"
        "BL      sub_FF8BD8B4\n"
        "MOV     R5, R0\n"
        "LDR     R0, [R4]\n"
        "LDR     R8, =0x43744\n"
        "CMP     R0, #0xB\n"
        "MOVEQ   R6, #0\n"
        "MOVEQ   R5, #0\n"
        "BEQ     loc_FF8BE77C\n"
        "CMP     R6, #1\n"
        "BNE     loc_FF8BE77C\n"
        "LDRSH   R0, [R4,#4]\n"
        "LDR     R1, =0xFF8BD608\n"
        "MOV     R2, #2\n"
        "BL      sub_FF959A58    \n"
        "STRH    R0, [R4,#4]\n"
        "MOV     R0, #0\n"
        "STR     R0, [R7,#0x28]\n"
        "B       loc_FF8BE784\n"
"loc_FF8BE77C:\n"
        "LDRH    R0, [R8]\n"
        "STRH    R0, [R4,#4]\n"
"loc_FF8BE784:\n"
        "CMP     R5, #1\n"
        "LDRNEH  R0, [R8,#8]\n"
        "BNE     loc_FF8BE7A0\n"
        "LDRSH   R0, [R4,#0xC]\n"
        "LDR     R1, =0xFF8BD68C\n"
        "MOV     R2, #0x20\n"
        "BL      sub_FF8C2208\n"
"loc_FF8BE7A0:\n"
        "STRH    R0, [R4,#0xC]\n"
        "LDRSH   R0, [R4,#6]\n"
        //"BL      sub_FF8B07EC    \n"
		"BL      sub_FF8B07EC_my\n" // -------------------->
        "LDRSH   R0, [R4,#8]\n"
        "MOV     R1, #1\n"
        "BL      sub_FF8B0F3C    \n"
        "MOV     R1, #0\n"
        "ADD     R0, R4, #8\n"
        "BL      sub_FF8B0FC4    \n"
        "LDRSH   R0, [R4,#0xE]\n"
        "BL      sub_FF8B8AA8    \n"
        "LDR     R4, =0xBB8\n"
        "CMP     R6, #1\n"
        "BNE     loc_FF8BE7F8\n"
        "LDR     R0, [R7,#0x1C]\n"
        "MOV     R2, R4\n"
        "MOV     R1, #2\n"
        "BL      sub_FF88489C    \n"
        "TST     R0, #1\n"
        "LDRNE   R1, =0x5A3\n"
        "LDRNE   R0, =0xFF8BDC88\n"
        "BLNE    sub_FF81E88C\n"
"loc_FF8BE7F8:\n"
        "CMP     R5, #1\n"
        "LDMNEFD SP!, {R4-R8,PC}\n"
        "LDR     R0, [R7,#0x1C]\n"
        "MOV     R2, R4\n"
        "MOV     R1, #0x20\n"
        "BL      sub_FF88489C    \n"
        "TST     R0, #1\n"
        "LDRNE   R1, =0x5A8\n"
        "LDRNE   R0, =0xFF8BDC88\n"
        "LDMNEFD SP!, {R4-R8,LR}\n"
        "BNE     sub_FF81E88C\n"
        "LDMFD   SP!, {R4-R8,PC}\n"
 );
};

void __attribute__((naked,noinline)) sub_FF8B07EC_my()
{  
 asm volatile(
        "STMFD   SP!, {R4-R6,LR}\n"
        "LDR     R5, =0x4150\n"
        "MOV     R4, R0\n"
        "LDR     R0, [R5,#4]\n"
        "CMP     R0, #1\n"
        "LDRNE   R1, =0x146\n"
        "LDRNE   R0, =0xFF8B05F0\n"
        "BLNE    sub_FF81E88C\n"
        "CMN     R4, #0xC00\n"
        "LDREQSH R4, [R5,#2]\n"
        "CMN     R4, #0xC00\n"
        "MOVEQ   R1, #0x14C\n"
        "LDREQ   R0, =0xFF8B05F0\n"
        "STRH    R4, [R5,#2]\n"
        "BLEQ    sub_FF81E88C\n"
        "MOV     R0, R4\n"
        "BL      apex2us\n"
        "MOV     R4, R0\n"
        "BL      sub_FF8F52BC\n"
        "MOV     R0, R4\n"
        "BL      sub_FF8FE188\n"
        "TST     R0, #1\n"
        "LDRNE   R1, =0x151\n"
        "LDMNEFD SP!, {R4-R6,LR}\n"
        "LDRNE   R0, =0xFF8B05F0\n"
        "BNE     sub_FF81E88C\n"
        "LDMFD   SP!, {R4-R6,PC}\n"
     );
};
